package com.ja.openchat.ui.me;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.Nullable;

import com.ja.openchat.BR;
import com.ja.openchat.R;
import com.ja.openchat.databinding.FragmentNearbyBinding;
import com.ja.openchat.viewmodels.NearbyViewModel;

import me.goldze.mvvmhabit.base.BaseFragment;

//附近人和公开群
public class NearbyFragment extends BaseFragment<FragmentNearbyBinding, NearbyViewModel> {


    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_nearby;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }


    @Override
    public void initView() {
        binding.refreshLayout.setEnableLoadMore(false);
    }

    @Override
    public void initData() {
        viewModel.setContext(getActivity());
        binding.refreshLayout.autoRefresh();
    }

    @Override
    public void initViewObservable() {
        //监听下拉刷新完成
        viewModel.uc.finishRefreshing.observe(this, o -> {
            //结束刷新
            binding.refreshLayout.finishRefresh();
        });
        //监听上拉加载完成
        viewModel.uc.finishLoadmore.observe(this, o -> {
            //结束刷新
            binding.refreshLayout.finishLoadMore();
        });
        //监听是否启用加载更多
        viewModel.uc.enableFinishLoadmore.observe(this, aBoolean -> {
            binding.refreshLayout.setEnableLoadMore(aBoolean);
        });
    }
}
